<template>
  <div>
    <Title title='错题管理'/>
    <div class="exam-list">
      <el-table
        :data="
          tableData.filter(
            (data) =>
              !search || data.name.toLowerCase().includes(search.toLowerCase())
          )
        "
        style="width: 100%"
      >
        <el-table-column label="Id">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="试卷名字">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </el-table-column>

        <el-table-column label="班级">
          <template slot-scope="scope">
            <span>{{ scope.row.className }}</span>
          </template>
        </el-table-column>
        <el-table-column label="得分">
          <template slot-scope="scope">
            <span>{{ scope.row.score }}</span>
          </template>
        </el-table-column>
        <el-table-column label="用时">
          <template slot-scope="scope">
            <span>{{ scope.row.time }}</span>
          </template>
        </el-table-column>
        <el-table-column label="答题时间">
          <template slot-scope="scope">
            <span>{{ scope.row.create_time }}</span>
          </template>
        </el-table-column>

        <el-table-column align="right">
          <template slot="header" slot-scope="scope">
            <el-input
              v-model="search"
              size="mini"
              placeholder="输入试卷名搜索"
            />
          </template>
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="handlePreview(scope.row.id, scope.row.name)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import {formatTime} from '@/utils'
import {getAnswer} from '@/api/paper'
import Title from '@/components/common/Title'
export default {
  data() {
    return {
      tableData: [],
      search: "",
    };
  },
  components: {
    Title
  },
  methods: {
      handlePreview(id) {
          this.$router.push({name: 'errorAnalysis', query: {ansId: id}})
      }
  },
  async created() {
      const res = await getAnswer()
      if (res.code === 1) {
          this.tableData = formatTime(res.data)
      } 
  }
};
</script>

<style lang="scss" scoped></style>
